package com.lcxw.hxzbadmin.common;

import com.alibaba.fastjson.JSONObject;
import com.lcxw.hxzbapi.controller.membercontroller.MemberRealization;
import com.lcxw.hxzbapi.service.AttentionService;
import com.lcxw.hxzbapi.service.PhotoService;
import com.lcxw.hxzbapi.service.YwpdConsumeService;
import com.lcxw.hxzbapi.tencentim.FeignService.ImManager;
import com.lcxw.hxzbapi.tencentim.common.TencentImConfig;
import com.lcxw.hxzbapi.tencentim.common.TencentImRealization;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.lcxw.hxzbapi.service.AddCoinService;
import com.lcxw.hxzbapi.service.CubeService;
import com.lcxw.hxzbapi.service.DuanweiService;
import com.lcxw.hxzbapi.service.GiftSendService;
import com.lcxw.hxzbapi.service.GiftService;
import com.lcxw.hxzbapi.service.RichLevelService;
import com.lcxw.hxzbapi.service.VipLevelService;
import com.lcxw.hxzbapi.service.YwpdChargeDetailService;
import com.lcxw.hxzbapi.service.YwpdMemberService;
import com.lcxw.hxzbapi.service.YwpdRoomService;
import com.lcxw.hxzbcommon.common.RedisUtils;

@Configuration
public class YwpdAdminConfig implements WebMvcConfigurer {

    @Bean
    public YwpdMemberService getYwpdMemberService() {
        return new YwpdMemberService();
    }

    @Bean
    public YwpdRoomService getYwpdRoomService() {
        return new YwpdRoomService();
    }

    @Bean
    public CubeService getCubeService() {
        return new CubeService();
    }

    @Bean
    public GiftService getGiftService() {
        return new GiftService();
    }

    @Bean
    public GiftSendService getGiftEarnService() {
        return new GiftSendService();
    }

    @Bean
    public RichLevelService getRichLevelService() {
        return new RichLevelService();
    }

    @Bean
    public VipLevelService getVipLevelService() {
        return new VipLevelService();
    }

    @Bean
    public DuanweiService getDuanweiService() {
        return new DuanweiService();
    }

    @Bean
    public YwpdChargeDetailService getYwpdChargeDetailService() {
        return new YwpdChargeDetailService();
    }

    @Bean
    public AddCoinService getAddCoinService() {
        return new AddCoinService();
    }

    @Bean
    public RedisUtils getRedisUtils() {
        return new RedisUtils();
    }

    @Bean
    public MemberRealization getMemberRealization() {
        return new MemberRealization();
    }

    @Bean
    public AttentionService getAttentionService() {
        return new AttentionService();
    }

    @Bean
    public TencentImRealization getTencentImRealization() {
        return new TencentImRealization();
    }

    @Bean
    public YwpdConsumeService getYwpdConsumeService() {
        return new YwpdConsumeService();
    }

    @Bean
    public TencentImConfig getTencentImConfig() {
        return new TencentImConfig();
    }

    @Bean
    public PhotoService getPhotoService() {
        return new PhotoService();
    }

    @Bean
    public ImManager getImUserManager() {
        return new ImManager() {
            @Override
            public String importAccount(long sdkappid, String identifier, String usersig,
                long random,
                JSONObject requestBody) {
                return null;
            }

            @Override
            public String updateUserInfo(long sdkappid, String identifier, String usersig,
                long random,
                JSONObject requestBody) {
                return null;
            }

            @Override
            public String sendGroupMsg(long sdkappid, String identifier, String usersig,
                long random,
                JSONObject requestBody) {
                return null;
            }

            @Override
            public String destroyGroup(long sdkappid, String identifier, String usersig,
                long random,
                JSONObject requestBody) {
                return null;
            }
        };
    }

    @Bean
    public YwpdInterceptor getYwpdInterceptor() {
        return new YwpdInterceptor();
    }

    @Bean
    public FilterRegistrationBean repeatedlyReadFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        RepeatedlyReadFilter repeatedlyReadFilter = new RepeatedlyReadFilter();
        registration.setFilter(repeatedlyReadFilter);
        registration.addUrlPatterns("/*");
        return registration;
    }

    /**
     * 拦截器的配置
     *
     * @param registry 入参
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //需要拦截的路径，/**表示需要拦截所有请求
        String[] addPathPatterns = {"/**"};
        //不需要拦截的路径
        String[] excludePathPaterns = {
            "/admin/login",
            "/feign/**"
//            "/admin/config/**",
//            "/admin/database/**"
        };
        //注册一个登录拦截器

        registry.addInterceptor(getYwpdInterceptor())
            .addPathPatterns(addPathPatterns)
            .excludePathPatterns(excludePathPaterns);
        //注册一个权限拦截器  如果有多个拦截器 ，只需要添加以下一行代码
        //registry.addInterceptor(new LoginInterceptor())
        // .addPathPatterns(addPathPatterns)
        // .excludePathPatterns(excludePathPatterns);

    }
}
